﻿using System.Collections.Generic;
using System.Reflection;
using System.Text;
using msilgc.cbuilder.CBuilder;
using msilgc.cbuilder.CSyntaxTree;
using msilgc.cbuilder.Reader;

namespace msilgc.cbuilder
{
    public class Compiler {
        public IEnumerable<ICMethodBody> TranslateMethods(IEnumerable<MethodInfo> methods) {
            foreach (var method in methods) {
                yield return TranslateMethod(method);
            }
        }

        public ICMethodBody TranslateMethod(MethodInfo method) {
            return new CMethodBodyFactory().Create(method);
        }

        public string DissassembleMethod(MethodInfo method) {
            MsilReader reader = new MsilReader(method);
            StringBuilder code = new StringBuilder();
            while (reader.Read(method)) {
                code.AppendLine(reader.Current.ToString());
            }
            return code.ToString();
        }
    }
}